﻿namespace NativeWin32
{
    using System;
    using System.Runtime.InteropServices;

    public static class HeaderDbghelp
    {
        public const uint MAX_PATH = 260;
        public const uint SYMOPT_CASE_INSENSITIVE = 1;
        public const uint SYMOPT_UNDNAME = 2;
        public const uint SYMOPT_DEFERRED_LOADS = 4;
        public const uint SYMOPT_NO_CPP = 8;
        public const uint SYMOPT_LOAD_LINES = 0x10;
        public const uint SYMOPT_OMAP_FIND_NEAREST = 0x20;
        public const uint SYMOPT_LOAD_ANYTHING = 0x40;
        public const uint SYMOPT_IGNORE_CVREC = 0x80;
        public const uint SYMOPT_NO_UNQUALIFIED_LOADS = 0x100;
        public const uint SYMOPT_FAIL_CRITICAL_ERRORS = 0x200;
        public const uint SYMOPT_EXACT_SYMBOLS = 0x400;
        public const uint SYMOPT_ALLOW_ABSOLUTE_SYMBOLS = 0x800;
        public const uint SYMOPT_IGNORE_NT_SYMPATH = 0x1000;
        public const uint SYMOPT_INCLUDE_32BIT_MODULES = 0x2000;
        public const uint SYMOPT_PUBLICS_ONLY = 0x4000;
        public const uint SYMOPT_NO_PUBLICS = 0x8000;
        public const uint SYMOPT_AUTO_PUBLICS = 0x10000;
        public const uint SYMOPT_NO_IMAGE_SEARCH = 0x20000;
        public const uint SYMOPT_SECURE = 0x40000;
        public const uint SYMOPT_DEBUG = 0x80000000;
        public const uint SYMOPT_ALLOW_ZERO_ADDRESS = 0x1000000;
        public const uint SYMF_OMAP_GENERATED = 1;
        public const uint SYMF_OMAP_MODIFIED = 2;
        public const uint SYMF_USER_GENERATED = 4;
        public const uint SYMF_REGISTER = 8;
        public const uint SYMF_REGREL = 0x10;
        public const uint SYMF_FRAMEREL = 0x20;
        public const uint SYMF_PARAMETER = 0x40;
        public const uint SYMF_LOCAL = 0x80;
        public const uint SYMF_CONSTANT = 0x100;
        public const uint SYMF_EXPORT = 0x200;
        public const uint SYMF_FORWARDER = 0x400;
        public const uint SYMF_FUNCTION = 0x800;
        public const uint SYMF_VIRTUAL = 0x1000;
        public const uint SYMF_THUNK = 0x2000;
        public const uint SYMF_TLSREL = 0x4000;
        public const uint MAX_SYM_NAME = 0x7d0;

        public enum BASIC_TYPE
        {
            btNoType = 0,
            btVoid = 1,
            btChar = 2,
            btWChar = 3,
            btInt = 6,
            btUInt = 7,
            btFloat = 8,
            btBCD = 9,
            btBool = 10,
            btLong = 13,
            btULong = 14,
            btCurrency = 0x19,
            btDate = 0x1a,
            btVariant = 0x1b,
            btComplex = 0x1c,
            btBit = 0x1d,
            btBSTR = 30,
            btHresult = 0x1f
        }

        public enum CV_access_e
        {
            CV_private = 1,
            CV_protected = 2,
            CV_public = 3
        }

        public enum CV_call_e
        {
            CV_CALL_NEAR_C,
            CV_CALL_FAR_C,
            CV_CALL_NEAR_PASCAL,
            CV_CALL_FAR_PASCAL,
            CV_CALL_NEAR_FAST,
            CV_CALL_FAR_FAST,
            CV_CALL_SKIPPED,
            CV_CALL_NEAR_STD,
            CV_CALL_FAR_STD,
            CV_CALL_NEAR_SYS,
            CV_CALL_FAR_SYS,
            CV_CALL_THISCALL,
            CV_CALL_MIPSCALL,
            CV_CALL_GENERIC,
            CV_CALL_ALPHACALL,
            CV_CALL_PPCCALL,
            CV_CALL_SHCALL,
            CV_CALL_ARMCALL,
            CV_CALL_AM33CALL,
            CV_CALL_TRICALL,
            CV_CALL_SH5CALL,
            CV_CALL_M32RCALL,
            CV_CALL_RESERVED
        }

        public enum DataKind
        {
            DataIsUnknown,
            DataIsLocal,
            DataIsStaticLocal,
            DataIsParam,
            DataIsObjectPtr,
            DataIsFileStatic,
            DataIsGlobal,
            DataIsMember,
            DataIsStaticMember,
            DataIsConstant
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct DBGHELP_MODLOAD_DATA
        {
            public uint ssize;
            public uint ssig;
            public IntPtr data;
            public uint size;
            public uint flags;
        }

        [StructLayout(LayoutKind.Sequential)]
        public class GUID
        {
            public uint Data1;
            public ushort Data2;
            public ushort Data3;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
            public byte[] Data4;
        }

        [StructLayout(LayoutKind.Sequential)]
        public class IMAGEHLP_MODULE64
        {
            public uint SizeOfStruct;
            public ulong BaseOfImage;
            public uint ImageSize;
            public uint TimeDateStamp;
            public uint CheckSum;
            public uint NumSyms;
            public HeaderDbghelp.SYM_TYPE SymType;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
            public string ModuleName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x100)]
            public string ImageName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x100)]
            public string LoadedImageName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x100)]
            public string LoadedPdbName;
            public uint CVSig;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 780)]
            public string CVData;
            public uint PdbSig;
            [MarshalAs(UnmanagedType.Struct)]
            public HeaderDbghelp.GUID PdbSig70;
            public uint PdbAge;
            public bool PdbUnmatched;
            public bool DbgUnmatched;
            public bool LineNumbers;
            public bool GlobalSymbols;
            public bool TypeInfo;
            public bool SourceIndexed;
            public bool Publics;
        }

        public enum IMAGEHLP_SYMBOL_TYPE_INFO
        {
            TI_GET_SYMTAG,
            TI_GET_SYMNAME,
            TI_GET_LENGTH,
            TI_GET_TYPE,
            TI_GET_TYPEID,
            TI_GET_BASETYPE,
            TI_GET_ARRAYINDEXTYPEID,
            TI_FINDCHILDREN,
            TI_GET_DATAKIND,
            TI_GET_ADDRESSOFFSET,
            TI_GET_OFFSET,
            TI_GET_VALUE,
            TI_GET_COUNT,
            TI_GET_CHILDRENCOUNT,
            TI_GET_BITPOSITION,
            TI_GET_VIRTUALBASECLASS,
            TI_GET_VIRTUALTABLESHAPEID,
            TI_GET_VIRTUALBASEPOINTEROFFSET,
            TI_GET_CLASSPARENTID,
            TI_GET_NESTED,
            TI_GET_SYMINDEX,
            TI_GET_LEXICALPARENT,
            TI_GET_ADDRESS,
            TI_GET_THISADJUST,
            TI_GET_UDTKIND,
            TI_IS_EQUIV_TO,
            TI_GET_CALLING_CONVENTION,
            TI_IS_CLOSE_EQUIV_TO,
            TI_GTIEX_REQS_VALID,
            TI_GET_VIRTUALBASEOFFSET,
            TI_GET_VIRTUALBASEDISPINDEX,
            TI_GET_IS_REFERENCE,
            TI_GET_INDIRECTVIRTUALBASECLASS
        }

        public enum SYM_TYPE
        {
            SymNone,
            SymCoff,
            SymCv,
            SymPdb,
            SymExport,
            SymDeferred,
            SymSym,
            SymDia,
            SymVirtual,
            NumSymTypes
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct SYMBOL_INFO
        {
            public uint SizeOfStruct;
            public uint TypeIndex;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2, ArraySubType = UnmanagedType.U8)]
            public ulong[] Reserved;
            public uint Reserved2;
            public uint Size;
            public ulong ModBase;
            public uint Flags;
            public ulong Value;
            public ulong Address;
            public uint Register;
            public uint Scope;
            public uint Tag;
            public uint NameLen;
            public uint MaxNameLen;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)]
            public string Name;
        }

        public enum SymTagEnum
        {
            SymTagNull,
            SymTagExe,
            SymTagCompiland,
            SymTagCompilandDetails,
            SymTagCompilandEnv,
            SymTagFunction,
            SymTagBlock,
            SymTagData,
            SymTagAnnotation,
            SymTagLabel,
            SymTagPublicSymbol,
            SymTagUDT,
            SymTagEnum,
            SymTagFunctionType,
            SymTagPointerType,
            SymTagArrayType,
            SymTagBaseType,
            SymTagTypedef,
            SymTagBaseClass,
            SymTagFriend,
            SymTagFunctionArgType,
            SymTagFuncDebugStart,
            SymTagFuncDebugEnd,
            SymTagUsingNamespace,
            SymTagVTableShape,
            SymTagVTable,
            SymTagCustom,
            SymTagThunk,
            SymTagCustomType,
            SymTagManagedType,
            SymTagDimension,
            SymTagMax
        }

        [StructLayout(LayoutKind.Sequential)]
        public class TI_FINDCHILDREN_PARAMS
        {
            public uint Count;
            public uint Start;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1, ArraySubType = UnmanagedType.U4)]
            public uint[] ChildId;
        }

        public enum UdtKind
        {
            UdtStruct,
            UdtClass,
            UdtUnion
        }
    }
}

